package com.sky.mapper.common;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Dish;
import com.sky.pojo.Setmeal;
import com.sky.pojo.SetmealDish;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SetmealMapper {

    // 查询指定分类id的套餐数量
    Integer countByCategoryId(Long id);

    //分页查询套餐
    Page<SetmealVO> findByPage(SetmealPageQueryDTO setmealPageQueryDTO);

    //新增套餐
    @AutoFill(OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id") // 获取生成的主键
    void add(Setmeal setmeal);


    //根据id查询套餐

    SetmealVO findSetmealById(Long id);

    //修改套餐
    void update(Setmeal setmeal);

    //设置套餐起售停售
    @AutoFill(OperationType.UPDATE)
    @Update("update setmeal set status = #{status},update_user = #{updateUser}, update_time = #{updateTime} where id = #{id}")
    void startOrStop(Setmeal setmeal);

    //批量删除套餐
    void delete(@Param("ids") List<Long> ids);

    //根据id删除套餐
    @Delete("delete from setmeal where id = #{id}")
    void deleteById(Long id);

    //根据分类id查询套餐
    List<SetmealVO> findSetmealBycategoryId(Integer categoryId);

    //根据套餐id查询包含的菜品
    @Select("select d.name,s.copies,d.image,d.description from setmeal_dish s join dish d on s.dish_id = d.id  where s.setmeal_id = #{id} ")
    List<DishItemVO> findDishBySetmealId(Long id);
}
